﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Digraphs
{
    public class Digraph
    {
        private int v;
        private int e;
        private List<int>[] adj;

        public Digraph(int V)
        {
            this.v = V;
            this.e = 0;
            adj = new List<int>[v];
            for (var i = 0; i < v; i++)
            {
                adj[i] = new List<int>();
            }
        }

        public int V()
        {
            return v;
        }

        public int E()
        {
            return e;
        }

        public List<int> Adj(int v)
        {
            return adj[v];
        }

        public void AddEdge(int v, int w)
        {
            adj[v].Add(w);
            e++;
        }

        public Digraph Reverse()
        {
            Digraph R = new Digraph(v);
            for (var i = 0; i < v; i++)
                foreach (var w in Adj(i))
                    R.AddEdge(w,i);

            return R;
        }
    }
}
